
package com.example.demodb.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.sql.Timestamp;
import java.util.Date;

@Entity
@Getter
@Setter
//@JsonInclude(JsonInclude.Include.NON_NULL)
@DynamicUpdate
@EntityListeners(AuditingEntityListener.class)
@Table(name = "user_song")
public class UserSong {
    @Column//加了@column后,就会在数据库中自动生成  user_id 这种命名格式的键
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @CreatedDate
    @Column(nullable = false, updatable = false)
    protected Long createTime = System.currentTimeMillis();

    @LastModifiedDate
    @Column
    protected Long updateTime = System.currentTimeMillis() ;

    @Column
    protected Integer listenCount=1;

    @ManyToOne
    @JoinColumn(name = "user_id")
    @JsonIgnore
    private User user;

    @ManyToOne
    @JoinColumn(name = "song_id")
    @JsonIgnoreProperties("userSongs")
    private Song song;
}
